global with sharing class InsertRole_Template
{
    
    WebService static String deleteRole(String templateId, String RoleId)
    {
        DataAccessControlUtil dacu = new DataAccessControlUtil();
        SObject trObj = new Template_Role__c();
        
        String message = dacu.isDeleteableObjectByUser(trObj);
        //Enters only if the User has permission to delete the object
        if(message.equalsIgnoreCase('success'))
        {
            Map<String, Schema.SObjectField> fieldMap = dacu.getFieldMap(trObj);
            
            String[] trExpectedFields = new String[]{'Id','Template_ID__c'}; 
            Set<String> allowedFields = dacu.getAccessibleFields(trObj, fieldMap, trExpectedFields);

            String constructSoql = '';
            if(!allowedFields.isEmpty())
            {
                constructSoql = 'Select ';
                for(String field: allowedFields)
                {
                    constructSoql += field+', ';
                }
                constructSoql = constructSoql.substring(0, constructSoql.length() - 2);
                constructSoql += ' from Template_Role__c  t where t.Id= :RoleId and t.Template_ID__c = :templateId';

                Template_Role__c[] tRole = Database.query(constructSoql);//[SELECT Id from Template_Role__c t where t.Id= :RoleId and t.Template_ID__c = :templateId];  
                if(tRole.size() > 0)
                {
                    if(tRole[0]!=null)
                        delete tRole[0];
                }
                return 'Deleted Successfully';
            }                
            
        }
        return message;
    }
   
    Webservice static String insertUrl(String url)
    {
        DataAccessControlUtil dacu = new DataAccessControlUtil();
        SObject sObj = new Url__c();
        
        String message = dacu.isCreateableObjectByUser(sObj);
        //Enters only if the User has permission to create the object
        if(message.equalsIgnoreCase('success'))
        {
            Map<String,Schema.SObjectField> fieldsMap = dacu.getFieldMap(sObj);
            URL__c u = new URL__c();
            sObj = u;
            
            //Only Url_Value__c needs to be inserted.
            //Note: Whenever a new Custom field has to be created, add it to the below Set.
            //Reason: The size of the below set will be compared with the size of the filtered set 
            Set<String> fieldsToBeCreatedList = new Set<String>{'Url_Value__c'};
            
            //Store the expected inserted fields and their values
            Map<String, Object> fieldsValMap = new Map<String, Object>();
            fieldsValMap.put('Url_Value__c', url);
            
            //Filter the above list to get the fields that can be created by the User. 
            Set<String> filteredList = dacu.getFilteredCreateableFields(fieldsMap, fieldsToBeCreatedList);
            
            //Enters only if the filteredList size is equivalent to the size of expected createable fields List 
            if(filteredList.size() == fieldsToBeCreatedList.size())
            {
                for(String s: filteredList)
                {
                    sObj.put(s, fieldsValMap.get(s));
                }
                //insert u;
                insert sObj;
            }
        }
        else
            return message;
        return 'success';
    }

    Webservice static String insertUrlBatchType(String url, String batchGenType)
    {
        SObject sobj = new URL__c();
        DataAccessControlUtil dacu = new DataAccessControlUtil();
        Map<String, Schema.SObjectField> urlSObjectFieldMap = dacu.getFieldMap(sObj);
            
        String[] roFields = new String[]{'Id', 'Url_Value__c', 'Plan_Doc_Type__c'}; 
        Set<String> allowedROFields = dacu.getAccessibleFields(sObj, urlSObjectFieldMap, roFields);
        String formSoql = '';                       
        if(!allowedROFields.isEmpty())
        {
            formSoql = 'Select ';
            for(String roField: allowedROFields)
            {
                formSoql += roField+', ';
            }
            formSoql = formSoql.substring(0, formSoql.length() - 2);
            formSoql += ' from Url__c ';

            URL__c[] uList = Database.query(formSoql);
            String message = '';
            if(uList.size() > 0)
            {
                message = dacu.isUpdateableObjectByUser(sObj);
                if(message.equalsIgnoreCase('success'))
                {

                    //Note: Whenever a new Custom field has to be updated, add it to the below Set.
                    //Reason: The size of the below set will be compared with the size of the filtered set 
                    Set<String> fieldsToBeUpdatedList = new Set<String>{'Url_Value__c', 'Plan_Doc_Type__c'};
                    
                    //Store the expected updated fields and their values
                    Map<String, Object> fieldsValMap = new Map<String, Object>();
                    fieldsValMap.put('Url_Value__c', url);
                    fieldsValMap.put('Plan_Doc_Type__c', batchGenType);
                    
                    //Filter the above list to get the fields that can be updated by the User. 
                    Set<String> filteredList = dacu.getFilteredUpdateableFields(urlSObjectFieldMap, fieldsToBeUpdatedList);
                    sObj = uList[0];
                    
                    //Enters only if the filteredList size is equivalent to the size of expected updateable fields List 
                    if(filteredList.size() == fieldsToBeUpdatedList.size())
                    {
                        for(String s: filteredList)
                        {
                            sObj.put(s, fieldsValMap.get(s));
                        }
                        //uList[0].Url_Value__c = url;
                        //uList[0].Plan_Doc_Type__c = batchGenType;
                        //update uList;
                        
                        update sObj;
                    }
                }
                else
                    return message;     
            }
            else
            {

                message = dacu.isCreateableObjectByUser(sObj);
                if(message.equalsIgnoreCase('success'))
                {
                    URL__c u = new URL__c();
                    sObj = u;
                    
                    //Note: Whenever a new Custom field has to be created, add it to the below Set.
                    //Reason: The size of the below set will be compared with the size of the filtered set 
                    Set<String> fieldsToBeCreatedList = new Set<String>{'Url_Value__c', 'Plan_Doc_Type__c'};
                    
                    //Store the expected inserted fields and their values
                    Map<String, Object> fieldsValMap = new Map<String, Object>();
                    fieldsValMap.put('Url_Value__c', url);
                    fieldsValMap.put('Plan_Doc_Type__c', batchGenType);

                    //Filter the above list to get the fields that can be created by the User. 
                    Set<String> filteredList = dacu.getFilteredCreateableFields(urlSObjectFieldMap, fieldsToBeCreatedList);
                    
                    //Enters only if the filteredList size is equivalent to the size of expected createable fields List 
                    if(filteredList.size() == fieldsToBeCreatedList.size())
                    {
                        for(String s: filteredList)
                        {
                            sObj.put(s, fieldsValMap.get(s));
                        }
                    
                        //u.Url_Value__c = url;
                        //u.Plan_Doc_Type__c = batchGenType;
                        //insert u;
                        insert sObj;
                    }
                }
                else
                    return message;
            }
        }
        return 'success'; 
    }
   
    Webservice static String upsertReportingManager(String rmVal)
    {
        SObject rmobj = new Reporting_Manager__c();
        DataAccessControlUtil dacu = new DataAccessControlUtil();
        
        //Enters only if User has permission to create and update the object
        if(dacu.isCreateableObjectByUser(rmObj) == 'success' && dacu.isUpdateableObjectByUser(rmObj) == 'success')
        {
            Map<String, Schema.Sobjectfield> fieldMap = dacu.getFieldMap(rmObj);
            
            //Following the below approach as the only field being accessed here is Reporting_Manager__c
            Schema.Describesobjectresult dsr = Reporting_Manager__c.sObjectType.getDescribe();
            Schema.Describefieldresult dfrRM = Reporting_Manager__c.Reporting_Manager__c.getDescribe();
            if(dsr.isAccessible() && dfrRM.isAccessible())
            {
                Reporting_Manager__c[] rmList = [select Reporting_Manager__c from Reporting_Manager__c];
                if(rmList.size() > 0)
                {
                    //Note: Whenever a new Custom field has to be updated, add it to the below Set.
                    //Reason: The size of the below set will be compared with the size of the filtered set 
                    Set<String> fieldsToBeUpdatedList = new Set<String>{'Reporting_Manager__c'};
                    
                    //Filter the above list to get the fields that can be updated by the User. 
                    Set<String> filteredList = dacu.getFilteredUpdateableFields(fieldMap, fieldsToBeUpdatedList);
                    
                    //Enters only if the retrieved filteredList size is equal to actual updateable fields list
                    if(filteredList.size() == fieldsToBeUpdatedList.size())
                    {
                        rmList[0].Reporting_Manager__c = rmVal;
                        update rmList;
                    }
                }
                else
                {
                    //Note: Whenever a new Custom field has to be created, add it to the below Set.
                    //Reason: The size of the below set will be compared with the size of the filtered set                  
                    Set<String> fieldsToBeCreatedList = new Set<String>{'Reporting_Manager__c'};
                    
                    //Filter the above list to get the fields that can be updated by the User. 
                    Set<String> filteredList = dacu.getFilteredCreateableFields(fieldMap, fieldsToBeCreatedList);
                    
                    //Enters only if the retrieved filteredList size is equal to actual createable fields list
                    if(filteredList.size() == fieldsToBeCreatedList.size())
                    {
                        Reporting_Manager__c rm = new Reporting_Manager__c(Reporting_Manager__c = rmVal);
                        insert rm;
                    }
                }
            }
        }
        return 'success'; 
    }
   
    Webservice static String[] getTitles()
    {
        String[] titles = new List<String>();
        Map<String,String> checkTitle = new Map<String, String>();
        SObject sobj = new User();
        DataAccessControlUtil dacu = new DataAccessControlUtil();
        Map<String, Schema.SObjectField> sObjectFieldMap = dacu.getFieldMap(sObj);
            
        String[] roFields = new String[]{'Title'}; 
        Set<String> allowedROFields = dacu.getAccessibleFields(sObj, sObjectFieldMap, roFields);
        String formSoql = '';                       
        if(!allowedROFields.isEmpty())
        {
            formSoql = 'Select ';
            for(String roField: allowedROFields)
            {
                formSoql += roField+', ';
            }
            formSoql = formSoql.substring(0, formSoql.length() - 2);
            String uTitle = '';
            formSoql += ' from User where Title != :uTitle order by Title ';

            for(User[] users: Database.query(formSoql))//[select Title from User where Title != '' order by Title])
            {
                for(User u:users)
                {
                    if(checkTitle.get(u.Title) == null)
                    {
                        checkTitle.put(u.Title, u.Title);
                        titles.add(u.Title);
                    }
                }
                if(titles.size() >= 1000)
                    break;
            }
            
        }
        return titles;
    }//end of getTitles()
    
    Webservice static TemplateDataMap__c getTemplateDetails(String templateId )
    {
        TemplateDataMap__c[] tdmList = null;
        String[] titles = new List<String>();
        Map<String,String> checkTitle = new Map<String, String>();
        
        SObject sobj = new TemplateDataMap__c();
        DataAccessControlUtil dacu = new DataAccessControlUtil();
        Map<String, Schema.SObjectField> sObjectFieldMap = dacu.getFieldMap(sObj);
            
        String[] roFields = new String[]{'id','Name1__c','Name2__c','Name3__c','Name4__c','Name5__c','Name6__c','Name7__c','Name8__c','Name9__c','Name10__c','Name11__c','Name12__c','Name13__c','Name14__c','Name15__c','Name16__c','Name17__c','Name18__c','Name19__c','Name20__c','Name21__c','Name22__c','Name23__c','Name24__c','Name25__c','Name26__c','Name27__c','Name28__c','Name29__c','Name30__c'}; 
        Set<String> allowedROFields = dacu.getAccessibleFields(sObj, sObjectFieldMap, roFields);
        String formSoql = '';                       
        if(!allowedROFields.isEmpty())
        {
            formSoql = 'Select ';
            for(String roField: allowedROFields)
            {
                formSoql += roField+', ';
            }
            formSoql = formSoql.substring(0, formSoql.length() - 2);
            formSoql += ' from TemplateDataMap__c';// where TemplateId__c = :templateId';
            roFields = new String[]{'TemplateId__c'}; 
            allowedROFields = dacu.getAccessibleFields(sObj, sObjectFieldMap, roFields);
            if(!allowedROFields.isEmpty())
            {
                formSoql += ' where '; 
                for(String roField: allowedROFields)
                {
                    formSoql += roField+' = :templateId ';
                }
                tdmList = Database.query(formSoql);//[select id, Name1__c, Name2__c, Name3__c, Name4__c, Name5__c, Name6__c, Name7__c, Name8__c, Name9__c, Name10__c, Name11__c, Name12__c, Name13__c, Name14__c, Name15__c, Name16__c, Name17__c, Name18__c, Name19__c, Name20__c, Name21__c, Name22__c, Name23__c, Name24__c, Name25__c, Name26__c, Name27__c, Name28__c, Name29__c, Name30__c from TemplateDataMap__c where TemplateId__c = :templateId];            
            }
        }
//      tdmList = [select id, Name1__c, Name2__c, Name3__c, Name4__c, Name5__c, Name6__c, Name7__c, Name8__c, Name9__c, Name10__c, Name11__c, Name12__c, Name13__c, Name14__c, Name15__c, Name16__c, Name17__c, Name18__c, Name19__c, Name20__c, Name21__c, Name22__c, Name23__c, Name24__c, Name25__c, Name26__c, Name27__c, Name28__c, Name29__c, Name30__c from TemplateDataMap__c where TemplateId__c = :templateId];
        return tdmList[0];  
    }

    Webservice static String updateTemplateDetails(String templateId )
    {
     /*   TemplateDataMap__c[] tdmList = null;
        tdmList = [select id, Name1__c, Name2__c, Name3__c, Name4__c, Name5__c, Name6__c, Name7__c, Name8__c, Name9__c, Name10__c, Name11__c, Name12__c, Name13__c, Name14__c, Name15__c, Name16__c, Name17__c, Name18__c, Name19__c, Name20__c, Name21__c, Name22__c, Name23__c, Name24__c, Name25__c, Name26__c, Name27__c, Name28__c, Name29__c, Name30__c from TemplateDataMap__c where TemplateId__c = :templateId];
        for(TemplateDataMap__c t: tdmList)
        {
            t.Name1__c = t.Name2__c = t.Name3__c = t.Name4__c = t.Name5__c = t.Name6__c = t.Name7__c = t.Name8__c = t.Name9__c = t.Name10__c = t.Name11__c = t.Name12__c = t.Name13__c = t.Name14__c = t.Name15__c = t.Name16__c = t.Name17__c = t.Name18__c = t.Name19__c = t.Name20__c = t.Name21__c = t.Name22__c = t.Name23__c = t.Name24__c = t.Name25__c = t.Name26__c = t.Name27__c = t.Name28__c = t.Name29__c = t.Name30__c = '';              
        }
        update tdmList; */
        return 'success';
    }


    WebService static String insertRecord(String roleId, String templateId)
    {
        SObject trObj = new Template_Role__c();
        SObject tObj = new Template__c();
        DataAccessControlUtil dacu = new DataAccessControlUtil();
        
        //Allow only if the user has permission to create Template_Role__c object and update Template__c object
        if(dacu.isCreateableObjectByUser(trObj) == 'success' && dacu.isUpdateableObjectByUser(tObj) == 'success')
        {
            Map<String, Schema.SObjectField> trFieldMap = dacu.getFieldMap(trObj);
            Map<String, Schema.SObjectField> tFieldMap = dacu.getFieldMap(tObj);
                
            String formSoql = '';                       
            String[] roFields = new String[]{'Role_ID__c', 'Template_ID__c'}; 
            Set<String> allowedROFields = dacu.getAccessibleFields(trObj, trFieldMap, roFields);
            if(!allowedROFields.isEmpty())
            {
                formSoql = 'Select ';
                for(String roField: allowedROFields)
                {
                    formSoql += roField+', ';
                }
                formSoql = formSoql.substring(0, formSoql.length() - 2);
                formSoql += ' from Template_Role__c  t where t.Role_ID__c= :roleId and t.Template_ID__c = :templateId';
    
                Template_Role__c[] tRole = Database.query(formSoql);//[SELECT Role_ID__c, Template_ID__c  from Template_Role__c t where t.Role_ID__c= :roleId and t.Template_ID__c = :templateId];
            
                 if(tRole.size() > 0)
                 {
                    return 'Record already exists';
                 }

                //Note: Whenever a new Custom field has to be updated, add it to the below Set.
                //Reason: The size of the below set will be compared with the size of the filtered set 
                Set<String> expectedUpdateableFields = new Set<String>{'EligibilityType__c'}; 
                Set<String> filteredFields = dacu.getFilteredUpdateableFields(tFieldMap, expectedUpdateableFields);
                
                //Allow to update the Template__c object only if the expected updateable fields size is equal to filtered fileds
                if(filteredFields.size() == expectedUpdateableFields.size())
                {
                    formSoql = 'Select Id, Name, ';
                    for(String field: filteredFields)
                    {
                        formSoql += field+', ';
                    }
                    formSoql = formSoql.substring(0, formSoql.length() - 2);
                    formSoql += ' from Template__c where Id = :templateId';

                     Template__c[] template = Database.query(formSoql);//[select Id, Name, EligibilityType__c from Template__c where Id = :templateId];
                     if(template.size() > 0)
                     {
                         template[0].EligibilityType__c = 'Role';
                     }
                     update template;
                }                
                 
                 UserRole[] ur = [select Name,RollupDescription from UserRole where Id = :roleId];
                 if(ur.size() > 0)
                 {
                    //Note: Whenever a new Custom field has to be created, add it to the below Set.
                    //Reason: The size of the below set will be compared with the size of the filtered set 
                    Set<String> expectedCreateableFields = new Set<String>{'Role_ID__c', 'Template_ID__c', 'Template__c' , 'Role_Name__c', 'Description__c'}; 
                    filteredFields = dacu.getFilteredCreateableFields(trFieldMap, expectedCreateableFields);
                    
                    //Allow to insert the Template_Role__c object only if the expected fields size is equal to filtered fileds
                    if(filteredFields.size() == expectedCreateableFields.size())
                    {
                         Template_Role__c tempRole = new Template_Role__c(Role_ID__c = roleId, Template_ID__c = templateId, Template__c = templateId, Role_Name__c = ur[0].Name, Description__c = ur[0].RollupDescription);
                         insert tempRole;
                    }
                 } 
                 return 'Record saved successfully';
            }
        }
        return 'failure';
    }

    WebService static String insertTitleRecord(String title, String templateId)
    {
        
        SObject trObj = new Template_Role__c();
        SObject tObj = new Template__c();
        DataAccessControlUtil dacu = new DataAccessControlUtil();
        
        //Allow only if the user has permission to create Template_Role__c object and update Template__c object
        if(dacu.isCreateableObjectByUser(trObj) == 'success' && dacu.isUpdateableObjectByUser(tObj) == 'success')
        {
            Map<String, Schema.SObjectField> trFieldMap = dacu.getFieldMap(trObj);
            Map<String, Schema.SObjectField> tFieldMap = dacu.getFieldMap(tObj);
                
            String formSoql = '';                       
            String[] roFields = new String[]{'Role_ID__c', 'Template_ID__c', 'User_Title__c'}; 
            Set<String> allowedROFields = dacu.getAccessibleFields(trObj, trFieldMap, roFields);
            if(!allowedROFields.isEmpty())
            {
                formSoql = 'Select ';
                for(String roField: allowedROFields)
                {
                    formSoql += roField+', ';
                }
                formSoql = formSoql.substring(0, formSoql.length() - 2);
                formSoql += ' from Template_Role__c  t where  t.User_Title__c= :title and t.Template_ID__c = :templateId';
    
                Template_Role__c[] tRole = Database.query(formSoql);//[SELECT Role_ID__c, Template_ID__c  from Template_Role__c t where t.Role_ID__c= :roleId and t.Template_ID__c = :templateId];
            
                 if(tRole.size() > 0)
                 {
                    return 'Record already exists';
                 }

                //Note: Whenever a new Custom field has to be updated, add it to the below Set.
                //Reason: The size of the below set will be compared with the size of the filtered set 
                Set<String> expectedUpdateableFields = new Set<String>{'EligibilityType__c'}; 
                Set<String> filteredFields = dacu.getFilteredUpdateableFields(tFieldMap, expectedUpdateableFields);

                //Allow to update the Template__c object only if the expected fields size is equal to filtered fileds
                if(filteredFields.size() == expectedUpdateableFields.size())
                {
                    formSoql = 'Select Id, Name, ';
                    for(String field: filteredFields)
                    {
                        formSoql += field+', ';
                    }
                    formSoql = formSoql.substring(0, formSoql.length() - 2);
                    formSoql += ' from Template__c where Id = :templateId';

                     Template__c[] template = Database.query(formSoql);//[select Id, Name, EligibilityType__c from Template__c where Id = :templateId];
                     if(template.size() > 0)
                     {
                         template[0].EligibilityType__c = 'Title';
                     }
                     update template;
                }                
                 
                //Note: Whenever a new Custom field has to be created, add it to the below Set.
                //Reason: The size of the below set will be compared with the size of the filtered set 
                Set<String> expectedCreateableFields = new Set<String>{'Template_ID__c', 'Template__c' , 'User_Title__c'}; 
                filteredFields = dacu.getFilteredCreateableFields(trFieldMap, expectedCreateableFields);
                
                //Allow to insert the Template_Role__c object only if the expected fields size is equal to filtered fileds
                if(filteredFields.size() == expectedCreateableFields.size())
                {
                    Template_Role__c tempRole = new Template_Role__c(Template_ID__c = templateId, Template__c = templateId, User_Title__c = title);
                    insert tempRole; 
                }
                 return 'Record saved successfully';
            }
        }
        
        return 'failure';
    }//end of insertTitleRecord()

    static testMethod void testCase() 
    {
    	try
    	{
	        InsertRole_Template irt = new InsertRole_Template();
	        UserRole[] ur = [select id from UserRole limit 1];
	        String roleId = ur[0].id;
	        
	        Template__c t1 = new Template__c(name = 'Insert Template2', EligibilityType__c = 'Title');
	        
	        Test.startTest();
	        
	        insert t1;
	        Template__c[] tempT = [select name from Template__c where id = :t1.id];
	        if(tempT.size() > 0)
	        	system.assertEquals(t1.name, tempT[0].name);
	        
	        String templateId = t1.id;
	        
	        System.assertEquals(insertTitleRecord('Manager', templateId), 'Record saved successfully');//(title, templateId)
	        insertTitleRecord('Manager', templateId);//(title, templateId)
	
	        Template__c t = new Template__c(name = 'Insert Template 2', EligibilityType__c = 'Role');
	        insert t;
	        tempT = [select name from Template__c where id = :t.id];
	        if(tempT.size() > 0)
		        system.assertEquals(t.name, tempT[0].name);
	        
	        
	        templateId = t.id;
	        TemplateDataMap__c tdm = new TemplateDataMap__c(TemplateId__c = templateId);
	        insert tdm;
	        System.assertEquals(templateId, tdm.TemplateId__c);
	        getTemplateDetails(templateId);
	        updateTemplateDetails(templateId);      
	        System.assertEquals(insertRecord(roleId, templateId), 'Record saved successfully');//(roleId, templateId)
	        insertRecord(roleId, templateId);
	        
	        String[] titles = getTitles();
	        Template_Role__c tr = new Template_Role__c(Template_ID__c = t.Id);
			insert tr;
	        Template_Role__c[] trT = [select Template_ID__c from Template_Role__c where id = :tr.id];
	        if(trT.size() > 0)
	        	system.assertEquals(tr.Template_ID__c, trT[0].Template_ID__c);
	        
	        Test.stopTest();
    	}
    	catch(Exception e){}            
    }
    
    static testMethod void testCase2() 
    {
    	try
    	{
	        Test.startTest();
	        InsertRole_Template irt = new InsertRole_Template();
	        system.assertEquals('success', upsertReportingManager('Rep_Manager2__c'));
	        system.assertEquals('success', insertUrlBatchType('', 'yes'));
	        System.assertEquals(insertUrl('http://na2.salesforce.com'), 'success');
	        
	        for(URL__c[] ul :[select id from Url__c])
	        {
	            delete ul;
	        }
	        
	        for(Reporting_Manager__c[] rm :[select id from Reporting_Manager__c])
	        {
	            delete rm;
	        }
	        system.assertEquals('success', upsertReportingManager('Rep_Manager2__c'));
	        system.assertEquals('success', insertUrlBatchType('', 'yes'));
	
	        Template__c t1 = new Template__c(name = 'Insert Template2', EligibilityType__c = 'Title');
	        
	        insert t1;
	        Template__c[] tempT = [select name from Template__c where id = :t1.id];
	        if(tempT.size() > 0)
	        	system.assertEquals(t1.name, tempT[0].name);
	        
	        String templateId = t1.id;
	        Template_Role__c tr = new Template_Role__c(Template_ID__c = t1.Id);
	        insert tr;
	        Template_Role__c[] trT = [select Template_ID__c from Template_Role__c where id = :tr.id];
	        if(trT.size() > 0)
	        	system.assertEquals(tr.Template_ID__c, trT[0].Template_ID__c);
	        String templateRoleId = tr.id;        
	        System.assertEquals(deleteRole(templateId, templateRoleId), 'Deleted Successfully');//templateId, roleId
	
	        Test.stopTest();  

        
    	}
    	catch(Exception e){}              
    }

    static testMethod void dacuTestCase() 
    {
        DataAccessControlUtil dacu = new DataAccessControlUtil();
        SObject sObj = new CallidusDataSOurce__c();
        Map<String, Schema.Sobjectfield> fieldsMap = dacu.getFieldMap(sObj);
        String[] expectedFieldMap = new String[]{'Id','Name'};
        Set<String> allowedFields = dacu.getAccessibleFields(sObj, fieldsMap, expectedFieldMap);
        Set<String> filteredList = dacu.getFilteredCreateableFields(fieldsMap, allowedFields);
        filteredList = dacu.getFilteredUpdateableFields(fieldsMap, allowedFields);
        system.assertEquals('success', dacu.isCreateableObjectByUser(sObj));
        system.assertEquals('success', dacu.isUpdateableObjectByUser(sObj));
        system.assertEquals('success', dacu.isDeleteableObjectByUser(sObj));
        dacu.pageMessage(sobj, 'create');
    }
    
}